package com.gykfbxxh.imovie.bean.news;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;

import com.app.utils.util.LogUtils;
import com.gykfbxxh.imovie.R;
import com.gykfbxxh.imovie.bean.film.FilmEntity;
import com.gykfbxxh.imovie.bean.film.FilmListEntity;
import com.gykfbxxh.imovie.utils.glide.ImageLoader;
import com.gykfbxxh.imovie.videoplayer.JCUserActionStandard;
import com.gykfbxxh.imovie.videoplayer.JCVideoPlayer;
import com.gykfbxxh.imovie.videoplayer.JCVideoPlayerStandard;

import java.util.ArrayList;
import java.util.List;


/**
 * 新闻列表的视频有边
 * Created by xuxinghai on 2016/7/17.
 */
public class ViewFilmsVideo_B implements JCUserActionStandard {

    public JCVideoPlayerStandard item_videoplayer;
    public RelativeLayout rl_autoview;
    public ImageView iv_leftsmallimg;
    public ViewFlipper viewflipper;
    public TextView tv_title;
    public TextView tv_type;
    public Context context;
    List<String> data = new ArrayList<>();

    public ViewFilmsVideo_B(View convertView) {
        initView(convertView);
    }

    public ViewFilmsVideo_B(View convertView, Context context) {
        this.context =context;
        initView(convertView);
    }


    /**
     * 初始化控件
     * @param convertView
     */
    public void initView(View convertView) {
        item_videoplayer = (JCVideoPlayerStandard) convertView.findViewById(R.id.item_videoplayer);
        item_videoplayer.setJcUserAction(this);
        viewflipper = (ViewFlipper) convertView.findViewById(R.id.viewflipper);
        rl_autoview = (RelativeLayout) convertView.findViewById(R.id.rl_autoview);
        iv_leftsmallimg = (ImageView) convertView.findViewById(R.id.iv_leftsmallimg);
        tv_title = (TextView) convertView.findViewById(R.id.tv_title);
        tv_type = (TextView) convertView.findViewById(R.id.tv_type);
        convertView.setTag(this);
    }

    /**
     * 加载数据
     * @param listBean
     */
    public void loadData(FilmListEntity listBean, int typeFlag){
        FilmEntity filmEntity = listBean.getFObject();
        tv_title.setText(listBean.getFName());
        ImageLoader.getInstance().listLoadImage2Cache(context,iv_leftsmallimg,listBean.getFObject().getFPhotos());
        tv_title.setText(listBean.getFName());
        tv_type.setText(listBean.getFObject().getFName());
        //加载视频
        if(!TextUtils.isEmpty(filmEntity.getFPhotow())){
            item_videoplayer.setUp(filmEntity.getFSourceurl(), JCVideoPlayer.SCREEN_LAYOUT_LIST,
                    filmEntity.getFName(), filmEntity.getFPhotow());
        }else{
            item_videoplayer.setUp(filmEntity.getFSourceurl(), JCVideoPlayer.SCREEN_LAYOUT_LIST,
                    filmEntity.getFName(), filmEntity.getFPhotow());
        }
        data.clear();
        data.add("好看好看真的很好看!");
        data.add("大片!超级大片!");
        data.add("精品!很不错的电影!");
        data.add("看了一遍没看够");
        data.add("不要疯狂的迷恋哥,哥只是个传说!");
        data.add("下蛋公鸡,公鸡中的战斗机.");
//        if("3".equals(typeFlag)) {
//            viewflipper.setTag(R.id.tag_third,filmEntity.getFName());
////            viewflipper.setVisibility(View.VISIBLE);
//            ViewFlipperUtils.getInstance().setFlipperView(viewflipper,data, (Activity) context);
////            ViewFlipperUtils.getInstance().startFlipper();
//        }else {
//            viewflipper.setVisibility(View.GONE);
//            AnimationUtils.getInstance().autoScrollAnimation((Activity) context,data,rl_autoview);
//        }
    }

    @Override
    public void onEvent(int type, String url, int screen, Object... objects) {
        LogUtils.e("xuxh","type="+type+" url="+url+" screen="+screen +" objects="+objects[0].toString());

        if(viewflipper!=null) {
            String playUrl = (String) viewflipper.getTag(R.id.tag_secong);
            if(!TextUtils.isEmpty(playUrl)&&!TextUtils.isEmpty(url)) {
                if(playUrl.equals(url)) {
                    viewflipper.stopFlipping();
                    viewflipper.setVisibility(View.GONE);
                }
            }
        }
    }
}
